﻿using System.Collections.Generic;

namespace HomeService.Models
{
    public class ServiceRequest
    {
        public ServiceRequest()
        {
            BasicInfo = new ServiceRequestBasicInfo();
            Photos = new List<ServiceRequestPhoto>();
        }

        public ServiceRequestBasicInfo BasicInfo { get; set; }
        public IList<ServiceRequestPhoto> Photos { get; private set; }
        
        public void Send()
        {
            // ValidateBasicInfo();
            ValidatePhotos();
            // Send the request
            Clear();
        }

        public void Clear()
        {
            BasicInfo = new ServiceRequestBasicInfo();
            Photos.Clear();
        }

        public void ValidatePhotos()
        {
            var validationException = new ValidationException<ServiceRequest>();
            if (Photos.Count == 0)
                validationException.AddErrorFor(x => x.Photos, "Liitä ainakin yksi kuva huoltopyyntöön.");
            validationException.ThrowIfErrors();
        }
    }
}